from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
import numpy as np

# 创建数据
X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([0, 0, 1, 1])

# 网格搜索
param_grid = {"C": [0.1, 1, 10], "kernel": ["linear", "rbf"]}
grid_search = GridSearchCV(SVC(), param_grid, cv=2)
grid_search.fit(X, y)

print("Best parameters:", grid_search.best_params_)